package com.example.enterprise.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(InValidateParamException.class)
    public Map handlerInvalidateParam(InValidateParamException e){
        //1.记录日志
        //2.发送邮件，短信，电话
        //3.给前段响应
        Map map = new HashMap<>();
        map.put("code",10001);
        map.put("msg",e.getMessage());
        return map;

    }
    @ExceptionHandler(Exception.class)
    public Map handlerGlobalException(Exception e){
        //1.记录日志
        //2.发送邮件，短信，电话
        //3.给前段响应
        Map map = new HashMap<>();
        map.put("code",-1);
        map.put("msg",e.getMessage());
        return map;

    }
}
